package com.kawaiior.asoulworld.capability;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.util.INBTSerializable;

public class AsoulAirPower implements INBTSerializable<NBTTagCompound> {

    private int health = 0;
    private double posX;
    private double posY;
    private double posZ;

    public double getPosX() {
        return posX;
    }

    public double getPosY(){return posY;}

    public double getPosZ() {
        return posZ;
    }

    public void setXYZ(double x, double y, double z){
        this.posX = x;
        this.posY = y;
        this.posZ = z;
    }

    public boolean hasHealth(){
        return this.health > 0;
    }

    public int getHealth() {
        return health;
    }

    public void cutHealth(World world){
        this.health--;
        if (this.health <= 0) {
            doTask(world);
        }
    }

    public void setHealth(int health) {
        this.health = health;
    }

    public void doTask(World world){
        for (int i = 0; i < 12; i++) {
            for (int j = 0; j < 12; j++) {
                world.setBlockToAir(new BlockPos(posX+i,posY,posZ+j));
                if (i==0 || i==11 || j==0 || j==11){
                    world.setBlockToAir(new BlockPos(posX+i,posY+1,posZ+j));
                }
            }
        }
    }

    @Override
    public NBTTagCompound serializeNBT() {
        NBTTagCompound nbt = new NBTTagCompound();
        nbt.setInteger("AsoulAirHealth", this.health);
        nbt.setDouble("AsoulAirDX", this.posX);
        nbt.setDouble("AsoulAirDY", this.posY);
        nbt.setDouble("AsoulAirDZ", this.posZ);

        return nbt;
    }

    @Override
    public void deserializeNBT(NBTTagCompound nbt) {
        this.health = nbt.getInteger("AsoulAirHealth");
        this.posX = nbt.getDouble("AsoulAirDX");
        this.posY = nbt.getDouble("AsoulAirDY");
        this.posZ = nbt.getDouble("AsoulAirDZ");
    }
}
